package com.ruoyi.web.controller.community;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.community.domain.CommunityRepair;
import com.ruoyi.community.service.ICommunityRepairService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 维修管理Controller
 * 
 * @author ruoyi
 * @date 2023-10-18
 */
@RestController
@RequestMapping("/community/repair")
public class CommunityRepairController extends BaseController
{
    @Autowired
    private ICommunityRepairService communityRepairService;

    /**
     * 查询维修管理列表
     */
    @PreAuthorize("@ss.hasPermi('community:repair:list')")
    @GetMapping("/list")
    public TableDataInfo list(CommunityRepair communityRepair)
    {
        startPage();
        List<CommunityRepair> list = communityRepairService.selectCommunityRepairList(communityRepair);
        return getDataTable(list);
    }

    /**
     * 导出维修管理列表
     */
    @PreAuthorize("@ss.hasPermi('community:repair:export')")
    @Log(title = "维修管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CommunityRepair communityRepair)
    {
        List<CommunityRepair> list = communityRepairService.selectCommunityRepairList(communityRepair);
        ExcelUtil<CommunityRepair> util = new ExcelUtil<CommunityRepair>(CommunityRepair.class);
        util.exportExcel(response, list, "维修管理数据");
    }

    /**
     * 获取维修管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('community:repair:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(communityRepairService.selectCommunityRepairById(id));
    }

    /**
     * 新增维修管理
     */
    @PreAuthorize("@ss.hasPermi('community:repair:add')")
    @Log(title = "维修管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CommunityRepair communityRepair)
    {
        return toAjax(communityRepairService.insertCommunityRepair(communityRepair));
    }

    /**
     * 修改维修管理
     */
    @PreAuthorize("@ss.hasPermi('community:repair:edit')")
    @Log(title = "维修管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CommunityRepair communityRepair)
    {
        return toAjax(communityRepairService.updateCommunityRepair(communityRepair));
    }

    /**
     * 删除维修管理
     */
    @PreAuthorize("@ss.hasPermi('community:repair:remove')")
    @Log(title = "维修管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(communityRepairService.deleteCommunityRepairByIds(ids));
    }
}
